﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace MoneyWentWhere.Utils
{
    public static class ReflectionExtensionMethods
    {
        public static bool HasAttribute<T>(this MemberInfo member) where T : Attribute
        {
            return member.GetCustomAttributes(typeof(T), true).Length > 0;
        }

        public static T GetAttribute<T>(this MemberInfo member) where T : Attribute
        {
            object[] attribs = member.GetCustomAttributes(typeof(T), true);
            if (attribs.Length == 0) { return null; }

            // TODO: warning if there are multiple
            return (T)attribs[0];
        }
    }
}
